<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <form action="/upload" method="post" enctype="multipart/form-data">
        <input type="file" name="file" id="file">
        <img src="" alt="" id="img">
        <button type="submit">上传</button>
    </form>
    <script>
        var file = document.querySelector('#file');
        var img = document.querySelector('#img');
        file.onchange = function(){
            // this.files[0]
            var fd = new FileReader();
            fd.readAsDataURL(this.files[0]);
            fd.onload = function(){
                img.src = this.result;
            }
        }
    </script>
</body>
</html>